layui.use(['layer', 'form', 'admin', 'ax', 'laydate','InsertSelect'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var laydate = layui.laydate;
    var layer = layui.layer;
    var  insertSelect = layui.InsertSelect;

    laydate.render({
        elem: '#kysj'
    });

    insertSelect.render({ elem: '#yyjlqy', data: []});

    /**
     * 检索营运经理
     */
    var languageAjax = new $ax(Feng.ctxPath + "/btyTxl/selectYy");
    var languageResult = languageAjax.start();
    $.each(languageResult, function (index, val) {
        $("#yyjlqy").append("<option value='" + val.yyjlqy + "'>" + val.yyjlqy + "</option>");
    });
    $("#yyjlqy").val($("#yyjl").val());
    form.render('select');

    form.on('select(yyjlqy)', function (data) {
        var regionOne = data.value;
        if (regionOne == "") {
            $("#yytel").html("");
            form.render('select');
        } else {
            var qyAjax = new $ax(Feng.ctxPath + "/btyTxl/selectYy");
            qyAjax.set("yyjl", regionOne);
            var qyResult = qyAjax.start();
            $("#yytel").val(qyResult[0].yytel);
            form.render('select');
        }
    });

    /**
     * 修改的时候去查询数据库中的不重复职位
     */

    // 表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/btyTxl/update", function (data) {
            if (data == 1) {
                Feng.error("该店已存在，请勿重复添加！！");
                return false;
            }
            if (data == 2) {
                Feng.error("餐厅编号重复！！");
                return false;
            }
            if (data == 0){
                Feng.success("修改成功！");
                //传给上个页面，刷新table用
                admin.putTempData('formOk', true);
                //关掉对话框
                admin.closeThisDialog();
            }
        }, function (data) {
            Feng.error("修改失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();

        //添加 return false 可成功跳转页面
        return false;
    });

});